﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DreamHome.Services;
using System.Configuration;
using MenuService.Public;


namespace DreamHome
{
    public class Application
    {
        private StaffService _staffService;
        private BranchService _branchService;

        public Application()
        {
            _staffService
                = new StaffService(
                    new Repositories.StaffRepository(
                        ConfigurationManager.AppSettings["FilePath"] ?? "storage.txt",
                        ConfigurationManager.AppSettings["DateFormat"] ?? @"dd\MM\yyyy",
                        ConfigurationManager.AppSettings["FileDelimeter"] ?? "\x0005"));
            //-----------
            _branchService
                = new BranchService(
                    new Repositories.BranchRepository(
                        ConfigurationManager.AppSettings["FilePathForBranch"] ?? "storage.txt",
                        ConfigurationManager.AppSettings["DateFormatForBranch"] ?? @"dd\MM\yyyy",
                        ConfigurationManager.AppSettings["FileDelimeterForBranch"] ?? "\x0005"));

        }

        public void Exit()
        {
            Environment.Exit(0);
        }

        public void Start()
        {
            MenuControlFacade menu = new MenuControlFacade("Menu.txt");
            menu.BindMethod("3", Exit);
            menu.BindMethod("1.1", _staffService.CreateStuff);
            menu.BindMethod("1.2", _staffService.UpdateStaff);
            menu.BindMethod("1.3.1", _staffService.DeleteEmploee);
            menu.BindMethod("1.4.1", _staffService.SelectAllFromStaffTable);
            menu.BindMethod("1.4.2", _staffService.SelectNameFromStaff);
            menu.BindMethod("2.1", _branchService.CreateBranch);
            menu.BindMethod("2.2", _branchService.SelectAllFromBranchTable);
            menu.BindMethod("1.4.3", _staffService.SelectManagerFromStaff);
            menu.BindMethod("1.4.4", _staffService.SelectStaffFromBranch);

            menu.PrintMenu2Console();
            menu.StartInputListening();
        }
    }
}
